package cn.com.roy.thread.t4_1_13.trylocktest;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Myservice {
    public ReentrantLock lock = new ReentrantLock();

    public void testMethod(){
       if(lock.tryLock()){ //仅在锁定未被其他线程保持时，获得锁定
           System.out.println(Thread.currentThread().getName() + "获得锁");
       }else{
           System.out.println(Thread.currentThread().getName() + "没有获得锁");
       }
    }
}
